/**
 * Created by sjswq on 2015/12/14.
 */
class Mediator extends egret.EventDispatcher {
    private static  _this:Mediator;
    private static  isSingleton:boolean = false;
    private static  _eventListener:any[] = [];//

    public constructor() {
        super();
        if (!Mediator.isSingleton) {
            console.log('不能实例化Mediator');
        }
        else {
            //init point
        }
        Mediator.isSingleton = false;
    }

    /**
     * ���ɵ���
     * @return  Observer
     */
    public static getInstance():Mediator {
        if (Mediator._this == null) {
            Mediator.isSingleton = true;
            Mediator._this = new Mediator();
        }
        return Mediator._this;
    }

    /**
     * @param    type
     * @param    listener
     * @param    useCapture
     * @param    priority
     * @param    useWeakReference
     * @return  void
     */
    public addEventListener(type:string, listener:Function, ob:any, useCapture:boolean = false, priority = 0):void {
        Mediator._eventListener.push(type);
        super.addEventListener(type, listener, ob, useCapture, priority);
    }

    /**
     * @param    type
     * @param    listener
     * @param    useCapture
     * @return  void
     */
    public removeEventListener(type:string, listener:Function, ob:any, useCapture:boolean = false):void {
        this.remove(type);
        super.removeEventListener(type, listener, ob, useCapture);
    }

    /**
     * @param    item
     * @return  void
     */
    private function

    remove(item:any):void {
        var index:number = Mediator._eventListener.indexOf(item);
        if (index >= 0) {
            Mediator._eventListener.splice(index, 1);
        }
        else {
            console.log(item);
        }
    }
}
